//
//  LESettingController.m
//  LoveExpressBusiness
//
//  Created by 刘甲奇 on 2017/5/11.
//  Copyright © 2017年 DFH. All rights reserved.
//

#import "LESettingController.h"
#import "LEDutyController.h"
#import "LEStoreModel.h"
#import "MakerTools.h"

@interface LESettingController ()

@property (weak, nonatomic) IBOutlet UISwitch *orderSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *employSwitch;

@end

@implementation LESettingController

- (void)setupUI
{
    [super setupUI];
    self.title = @"系统设置";
    LEStoreModel *store = [MakerTools readFromSandBox:Store_Info];
    if ([store.store_orders_delivery isEqualToString:@"1"])
    {
        [self.orderSwitch setOn:YES];
    }else{
        [self.orderSwitch setOn:NO];
    }
    if ([store.store_recruit isEqualToString:@"1"])
    {
        [self.employSwitch setOn:YES];
    }else{
        [self.employSwitch setOn:NO];
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.tabBarController.tabBar setHidden:YES];
}
#pragma mark- 网络请求 
/**
 自动派单.招聘
 */
- (void)requestAutoSendOrder:(NSDictionary *)param
{
    [API requestPostAppendKey:StoreAutoSendOrderUrl params:param success:^(NSDictionary *successCode) {
        id datas = successCode[@"datas"];
        if ([datas isKindOfClass:[NSDictionary class]])
        {
            NSString *error = datas[@"error"];
            if (error)
            {
                [SVProgressHUD showErrorWithStatus:error];
            }
        }else if ([datas isKindOfClass:[NSString class]])
        {
            [SVProgressHUD showSuccessWithStatus:datas];
        }
    } falure:^(NSError *er) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
    
}
#pragma mark- 点击事件
- (IBAction)autoOrderClick:(UISwitch *)sender {
    LELog(@"%s---%d---%d",__func__,__LINE__,sender.on);
    LEStoreModel *store = [MakerTools readFromSandBox:Store_Info];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    if (sender.on) {
        store.store_orders_delivery = @"1";
        [param setObject:@"store_orders_delivery|1" forKey:@"param"];

    }else{
        store.store_orders_delivery = @"2";
        [param setObject:@"store_orders_delivery|2" forKey:@"param"];
    }
    [MakerTools saveToSandBox:Store_Info withSavedObject:store];
    [self requestAutoSendOrder:param];
}
- (IBAction)emplyClick:(UISwitch *)sender {
    LELog(@"%s---%d---%d",__func__,__LINE__,sender.on);
    LEStoreModel *store = [MakerTools readFromSandBox:Store_Info];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    if (sender.on) {
        store.store_recruit = @"1";
        [param setObject:@"store_recruit|1" forKey:@"param"];
    }else
    {
        store.store_recruit = @"0";
        [param setObject:@"store_recruit|0" forKey:@"param"];
    }
    [MakerTools saveToSandBox:Store_Info withSavedObject:store];
    [self requestAutoSendOrder:param];
}
- (IBAction)authorInfoClick:(UIButton *)sender {
    LELog(@"%s---%d---点击授权",__func__,__LINE__);
    LEDutyController *duty = [[LEDutyController alloc] init];
    [self.navigationController pushViewController:duty animated:YES];
}
- (IBAction)dutyClick:(UIButton *)sender {
    LELog(@"%s---%d---点击免责",__func__,__LINE__);
}


@end
